<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Card_apply;
use App\Models\Card;

class CardRecordController extends Controller
{
    public function index(Request $request){
        $where = function ($query) use ($request) {
            if ($request->has('mobile') and $request->mobile != '') {
                $query->where('mobile', $request->mobile);
            }

            if($request->has('name') and $request->name != '') {
                $query->where('name',$request->name);
            }
        };
        $records = Card_apply::where($where)
            ->where('card_id','<>','')->orderBy('create_time','desc')
            ->paginate(10);
        $Card = new Card();

        foreach ($records as $key=>&$value){
            if($value['card_id'] != ''){
                $res = $Card->find($value['card_id']);
                $value['cardname'] = $res['name'];
            }
            if($value['user_id'] != ''){
                $res = $Card->find($value['user_id']);
                $value['nickname'] = $res['nickname'];
            }
        }
        //return $records;
        return view('admin.cardapply.index', compact('records'));
    }
}


